package com.dogkr.server.entity;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.List;

import com.dogkr.server.entity.Order.OrderStatus;
import com.sean.common.utils.DateUtils;
import com.sean.common.utils.StringUtils;

public class Order {
	
    private Long id;

    private Long hostId;

    private String hostName;
    
    private String orderNo;

    private Long userId;

    private String userName;

    private BigDecimal orderAmount;

    private BigDecimal orderStrikePrice;

    private Date orderStartDate;

    private Date orderEndDate;

    private Date lastModifydate;

    private Date createDate;

    private Short status;

    private String hostRemark;

    private String userRemark;
    
    private String appraise;
    
    private BigDecimal evaluate;
    
    private List<OrderPet> petList;

	private boolean isUser;

	private boolean isHost;
	
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getHostId() {
        return hostId;
    }

    public void setHostId(Long hostId) {
        this.hostId = hostId;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

	public BigDecimal getEvaluate() {
		return evaluate;
	}

	public void setEvaluate(BigDecimal evaluate) {
		this.evaluate = evaluate;
	}

	public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public BigDecimal getOrderAmount() {
        return orderAmount;
    }

    public void setOrderAmount(BigDecimal orderAmount) {
        this.orderAmount = orderAmount;
    }

    public BigDecimal getOrderStrikePrice() {
        return orderStrikePrice;
    }

    public void setOrderStrikePrice(BigDecimal orderStrikePrice) {
        this.orderStrikePrice = orderStrikePrice;
    }

    public Date getOrderStartDate() {
        return orderStartDate;
    }

    public void setOrderStartDate(Date orderStartDate) {
        this.orderStartDate = orderStartDate;
    }

    public Date getOrderEndDate() {
        return orderEndDate;
    }

    public void setOrderEndDate(Date orderEndDate) {
        this.orderEndDate = orderEndDate;
    }

    public Date getLastModifydate() {
        return lastModifydate;
    }

    public void setLastModifydate(Date lastModifydate) {
        this.lastModifydate = lastModifydate;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Short getStatus() {
        return status;
    }

    public void setStatus(Short status) {
        this.status = status;
    }

    public String getHostRemark() {
        return hostRemark;
    }

    public void setHostRemark(String hostRemark) {
        this.hostRemark = hostRemark;
    }

    public String getUserRemark() {
        return userRemark;
    }

    public void setUserRemark(String userRemark) {
        this.userRemark = userRemark;
    }

	public List<OrderPet> getPetList() {
		return petList;
	}

	public void setPetList(List<OrderPet> petList) {
		this.petList = petList;
	}
	
	public boolean getIsUser() {
		return isUser;
	}

	public boolean getIsHost() {
		return isHost;
	}
	
	public String getAppraise() {
		return appraise;
	}

	public void setAppraise(String appraise) {
		this.appraise = appraise;
	}

	public boolean isMyOrder(User user) {
		if(this.userId == user.getId()) {
			this.isUser = true;
			return true;
		} else if(user.getHost() != null && this.hostId.equals(user.getHost().getId())) {
			this.isHost = true;
			return true;
		}
		return false;
	}
	
	public int getDays() throws ParseException {
		return DateUtils.getDays(this.orderStartDate, this.orderEndDate);
	}
	
	/**
	 * 订单状态.
	 * @author XinWang
	 *
	 */
	public enum OrderStatus{
		/**
		 * 创建预约
		 */
		CREATE(10),
		/**
		 * 拒绝预约
		 */
		REJECT(20),
		
		/**
		 * 同意预约
		 */
		AGREE(30),
		
		/**
		 * 已评价
		 */
		ASSESS(40),
		/**
		 * 付款过期
		 */
		ORDER_DATED(50),
		/**
		 * 已报价/等待付款
		 */
		QUOTATION(100),
		/**
		 * 已付款
		 */
		PAID(110),
		/**
		 * 付款过期
		 */
		PAID_DATED(120),
		/**
		 * 已退款
		 */
		REBATE(130);
		
		private short status;
		
		OrderStatus(int status) {
			this.status = (short) status;
		}
		
		public short getVal(){
			return this.status;
		}
	}

	public void setStatus(OrderStatus quotation) {
		this.status = quotation.getVal();
		this.lastModifydate = new Date();
	}
}